#include <iostream>
#include <vector>

using namespace std;

// 153. 寻找旋转排序数组中的最小值
// https://leetcode.cn/problems/find-minimum-in-rotated-sorted-array/description/

class Solution {
public:
    int findMin(vector<int>& nums) {
        int left = 0;
        int right = nums.size() - 1;
        int ans = 0;
        while (left <= right)
        {
            int mid = (right - left) / 2 + left;
            if(nums[mid] >= nums[right]){
                ans = left;
                left = mid + 1;
            }else{
                right = mid;
            }
        }
        return nums[ans];
    }
};

int main()
{
    vector<int> nums{3, 4, 5, 1, 2};
    Solution solution{};
    cout << solution.findMin(nums);
    return 0;
}